package compareResult.datasetCompare;

import socketEnv.DataUtil;

import java.io.File;

import static socketEnv.DataUtil.ensureReachable;

/**
 * Created by hanyz on 2017/1/6.
 */
public class FileComparer {
    public static boolean compare(String expFilePath, String actualFilePath) throws Exception {
        boolean compareResult = false;
        compareResult = EqualAssert.isFileEqual(expFilePath, actualFilePath);
        if(!compareResult){
            throw new Exception(expFilePath+","+actualFilePath+" compareError.");
        }
        return compareResult;
    }

    /**
     * 比较结果文件，exp文件目录与actual文件目录对应时可以只传入结果目录
     *支持两种格式："DataConversion/testExportData/" ；DataUtil.resultPath_actual + "DataConversion/testExportData/"
     * @param resultPath
     * @return
     */
    public static boolean compare(String resultPath) throws Exception {
        String expPath;
        String actualPath = resultPath;
        if(resultPath.contains(DataUtil.resultPath_actual)){
            String sub = resultPath.substring(resultPath.lastIndexOf("actual")+7,resultPath.length());
            expPath = DataUtil.resultPath_exp + sub;
        }
        else{
            expPath =  DataUtil.resultPath_exp + resultPath;
            actualPath = DataUtil.resultPath_actual + resultPath;
        }
        return compare(actualPath, expPath);
    }


    /**
     * 批量比较结果文件，exp文件目录与actual文件目录对应时可以只传入结果目录
     * @param resultPaths
     * @return
     * @throws Exception
     */
    public static boolean compare(String[] resultPaths) throws Exception {
       // ensureReachable();
        boolean compareResult = true;
        for(int i=4;i<resultPaths.length;i++){
            compareResult = compare(resultPaths[i]);
        }
        return compareResult;
    }
}
